﻿package com.pandemicode.framework.utils {
	import com.pandemicode.framework.interfaces.IDisposeable;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.InteractiveObject;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.IEventDispatcher;
	import flash.text.TextField;
	
	/**
	* @author Michael Lawrence
	* @version 1.0.0
	*/
	public class Filter {
		/**
		 * A series of methods for filtering arrays using the array.filter method.
		 */
		public function Filter() { }
		
		/**
		 * Determines whether the element in an array is of the IEventDispatcher type.
		 * @param	element	The current element in the array.
		 * @param	index	The index of the current element in the array.
		 * @param	array	The full array the element is in.
		 * @return	Returns whether the element in an array is of the IEventDispatcher type.
		 */
		public static function isIEventDispatcher(element:*, index:int, array:Array):Boolean {
			return element is IEventDispatcher;
		}
		
		/**
		 * Determines whether the element in an array is of the MovieClip type.
		 * @param	element	The current element in the array.
		 * @param	index	The index of the current element in the array.
		 * @param	array	The full array the element is in.
		 * @return	Returns whether the element in an array is of the MovieClip type.
		 */
		public static function isMovieClip(element:*, index:int, array:Array):Boolean {
			return element is MovieClip;
		}
		
		/**
		 * Determines whether the element in an array is of the Sprite type.
		 * @param	element	The current element in the array.
		 * @param	index	The index of the current element in the array.
		 * @param	array	The full array the element is in.
		 * @return	Returns whether the element in an array is of the Sprite type.
		 */
		public static function isSprite(element:*, index:int, array:Array):Boolean {
			return element is Sprite;
		}
		
		/**
		 * Determines whether the element in an array is of the InteractiveObject type.
		 * @param	element	The current element in the array.
		 * @param	index	The index of the current element in the array.
		 * @param	array	The full array the element is in.
		 * @return	Returns whether the element in an array is of the InteractiveObject type.
		 */
		public static function isInteractiveObject(element:*, index:int, array:Array):Boolean {
			return element is InteractiveObject;
		}
		
		/**
		 * Determines whether the element in an array is a valid email address.
		 * @param	element	The current element in the array.
		 * @param	index	The index of the current element in the array.
		 * @param	array	The full array the element is in.
		 * @return	Returns whether the element in an array is a valid email address.
		 */
		public static function isValidEmail(element:*, index:int, array:Array):Boolean {
			if (element is String) {
				var email:String = element as String;
				return RegEx.isValidEmail(StringUtils.removeExtraWhitespace(email));
			} else return false;
		}
		
		/**
		 * Determines whether the element in an array is of the Number type.
		 * @param	element	The current element in the array.
		 * @param	index	The index of the current element in the array.
		 * @param	array	The full array the element is in.
		 * @return	Returns whether the element in an array is of the Number type.
		 */
		public static function isNumber(element:*, index:int, array:Array):Boolean {
			return element is Number;
		}
		
		/**
		 * Determines whether the element in an array is of the TextField type.
		 * @param	element	The current element in the array.
		 * @param	index	The index of the current element in the array.
		 * @param	array	The full array the element is in.
		 * @return	Returns whether the element in an array is of the TextField type.
		 */
		public static function isTextField(element:*, index:int, array:Array):Boolean {
			return element is TextField;
		}
		
		/**
		 * Determines whether the element in an array is of the Bitmap type.
		 * @param	element	The current element in the array.
		 * @param	index	The index of the current element in the array.
		 * @param	array	The full array the element is in.
		 * @return	Returns whether the element in an array is of the Bitmap type.
		 */
		public static function isBitmap(element:*, index:int, array:Array):Boolean {
			return element is Bitmap;
		}
		
		/**
		 * Determines whether the element in an array is of the BitmapData type.
		 * @param	element	The current element in the array.
		 * @param	index	The index of the current element in the array.
		 * @param	array	The full array the element is in.
		 * @return	Returns whether the element in an array is of the BitmapData type.
		 */
		public static function isBitmapData(element:*, index:int, array:Array):Boolean {
			return element is BitmapData;
		}
		
		/**
		 * Determines whether the element in an array is of the Loader type.
		 * @param	element	The current element in the array.
		 * @param	index	The index of the current element in the array.
		 * @param	array	The full array the element is in.
		 * @return	Returns whether the element in an array is of the Loader type.
		 */
		public static function isLoader(element:*, index:int, array:Array):Boolean {
			return element is Loader;
		}
		
		/**
		 * Determines whether the element in an array is of the Shape type.
		 * @param	element	The current element in the array.
		 * @param	index	The index of the current element in the array.
		 * @param	array	The full array the element is in.
		 * @return	Returns whether the element in an array is of the Shape type.
		 */
		public static function isShape(element:*, index:int, array:Array):Boolean {
			return element is Shape;
		}
		
		/**
		 * Determines whether the element in an array is of the IDisposeable type.
		 * @param	element	The current element in the array.
		 * @param	index	The index of the current element in the array.
		 * @param	array	The full array the element is in.
		 * @return	Returns whether the element in an array is of the IDisposeable type.
		 */
		public static function isIDisposeable(element:*, index:int, array:Array):Boolean {
			return element is IDisposeable;
		}
		
		/**
		 * Determines whether the element in an array is of the DisplayObject type.
		 * @param	element	The current element in the array.
		 * @param	index	The index of the current element in the array.
		 * @param	array	The full array the element is in.
		 * @return	Returns whether the element in an array is of the DisplayObject type.
		 */
		public static function isDisplayObject(element:*, index:int, array:Array):Boolean {
			return element is DisplayObject;
		}
	}
}